
#include "Defines.h"
#include <list>
#include <string>

class Value
{
public:
	Value() {}
	Value(int32 i)  { m_data.push_back(new Data(i)); }
	Value(uint32 i) { m_data.push_back(new Data(i)); }
	Value(char c)   { m_data.push_back(new Data(c)); }
	Value(const std::string& text) { m_data.push_back(new Data(text)); }
	Value(const char* text) { m_data.push_back(new Data(std::string(text))); }
	~Value();

	enum DataType {
		TYPE_INT,
		TYPE_CHAR,
		TYPE_UINT,
		TYPE_STRING,
		TYPE_INVALID
	};


	inline int16 GetType() const { return m_data.size() ? m_data.front()->m_type : -1; }
	void Clear();
	inline uint16 size() const { return (uint16)m_data.size(); }

	operator int32()const;
	operator uint32() const;	
	operator std::string() const;
	operator char() const;

	bool operator==(const Value& value);
	bool operator!=(const Value& value);
	bool operator>(const Value& value);
	bool operator<(const Value& value);

private:
	struct Data {
		Data(int32 i)	{ m_data = new int32(i);   m_type = TYPE_INT; }
		Data(uint32 ui) { m_data = new uint32(ui); m_type = TYPE_UINT; }
		Data(const std::string& text) { m_data = new std::string(text); m_type = TYPE_STRING; }
		Data(char c) { m_data = new char(c); m_type = TYPE_CHAR; }
		~Data();

		void* m_data;
		int m_type;

	private:
		Data();
	};

	std::list<Data*> m_data;
	static std::string error;

	template<class T>
	friend Value& operator<<(Value& v, T type);

	template<class T>
	friend Value& operator>>(Value& v, T& type);

	friend std::ostream& operator<<(std::ostream&, const Value&);

};


template<class T>
Value& operator<<( Value& v, T type )
{
	v.m_data.push_back(new Value::Data(type));
	return v;
}
template<class T>
Value& operator>>( Value& v, T& type )
{
	if(!v.m_data.size()) return v;
	Value::Data* temp = v.m_data.front();
	type = v;				//converts to the type if possible 
	delete temp;			//free memory
	v.m_data.pop_front();	//pop the last element
	return v;
}